package com.matriq.cloudmanager;

import java.util.ArrayList;
import java.util.List;

import com.matriq.cloudmanager.R;
import com.matriq.cloudmanager.fragment.CourseEvalListFragment;
import com.matriq.cloudmanager.fragment.MycourseFragment;
import com.matriq.cloudmanager.fragment.ZhpjFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import net.lgpage.activity.BaseFragmentActivity;
import net.lgpage.util.MyFragmentPagerAdapter;

public class MycourseActivity extends BaseFragmentActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_mycourse);
		setViews();
		setEvents();
		loadData();
	}

	LinearLayout viewActionBar;
	TextView tv_tab[] = new TextView[3];
	android.support.v4.view.ViewPager vp;
	RelativeLayout rl_tab[] = new RelativeLayout[3];
	ImageButton ll_back;
	View v_tab[] = new View[3];

	List<Fragment>fmlist;
	private void setViews() {
		viewActionBar = (LinearLayout) this.findViewById(R.id.viewActionBar);
		tv_tab[0] = (TextView) this.findViewById(R.id.tv_tab0);
		tv_tab[1] = (TextView) this.findViewById(R.id.tv_tab1);
		tv_tab[2] = (TextView) this.findViewById(R.id.tv_tab2);
		vp = (android.support.v4.view.ViewPager) this.findViewById(R.id.vp);
		fmlist = new ArrayList<>();
		fmlist.add(new MycourseFragment());
		fmlist.add(new MycourseFragment());
		fmlist.add(new MycourseFragment());
		pa = new MyFragmentPagerAdapter(getSupportFragmentManager(),fmlist);
		vp.setAdapter(pa);
		rl_tab[0] = (RelativeLayout) this.findViewById(R.id.rl_tab0);
		rl_tab[1] = (RelativeLayout) this.findViewById(R.id.rl_tab1);
		rl_tab[2] = (RelativeLayout) this.findViewById(R.id.rl_tab2);
		ll_back = (ImageButton) this.findViewById(R.id.ll_back);
		v_tab[0] = (View) this.findViewById(R.id.v_tab0);
		v_tab[1] = (View) this.findViewById(R.id.v_tab1);
		v_tab[2] = (View) this.findViewById(R.id.v_tab2);
	}

	private void setEvents() {
		vp.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				changeTab(position);
			}

			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});
		for (int i = 0; i < rl_tab.length; i++) {
			rl_tab[i].setTag(i);
			rl_tab[i].setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					changeTab((int) v.getTag());
				}
			});
		}
	}
	private void changeTab(int index) {
		for (int i = 0; i < tv_tab.length; i++) {
			v_tab[i].setVisibility(View.INVISIBLE);
			tv_tab[i].setTextColor(0xb4282828);
		}
		tv_tab[index].setTextColor(0xff282828);
		v_tab[index].setVisibility(View.VISIBLE);
		vp.setCurrentItem(index);
	}
	PagerAdapter pa;

	class ViewHolder {
		ImageView iv;
	}


	private void loadData() {
		changeTab(0);
	}

	@Override
	public void onDestroy() {
		
		super.onDestroy();
	}

}